*In this RDC code, all variables and output labled 'capT' correspond to those labeled 'xi' 
*elsewhere in the code as well as in the text.

*This code mirrors the BvD code. For explainations for some anlyses, see the comments there
clear
macro drop all

*Insert your file path here:
global proj ""
global data ""
global code ""
global results ""
global date ""

global masteriter = 1000
*******************************************************************************

*Prep files for main tables and figures
 global samplelist all young old youngold  highcutoff digit6 all_uw all_w0 all_w25 all_va
  global routine ""

*This dataset brings in lbd and census of manufacturing data from 2012, including TFP files.
*Datasets should be copied over to the ${data} directory in STATA format.
do "${code}/Fromrawdata.do"

 do "${code}/Makedata.do"
 do "${code}/Raw.do"
 do "${code}/Permute.do"
 do "${code}/Cov.do"

 do "${code}/Youngold.do"

*Table.do creates all tables. Based on the value of the global varible ${routine}, 
*it draws from different datasets and outputs different files (as stated before its invocation) 
 
*Table 1
do "${code}/Table.do"

*Figures 1a and 1b
do "${code}/Fig1.do"

*Figures 2a and 2b
do "${code}/Fig2.do"


/*Figures 3 and 5: This generates Figures 5a and 5b, and a dataset with
the datapoints needed to plot Figures 3 and 5c and 5d. The slopes, and other numbers 
printed on the figures are produced above in Cov.do and Youngold.do (for Figures 
3 and 5, respectively) and can be found in output datasets generated by those codes. 
See the comments in those do files. */
do "${code}/Fig3_and_5.do"

*Thresholdloop (Figures 4 and A.3): this file generates a dataset with all points
* needed to graph the two figures.
do "${code}/Submaster_threshold.do"


*Value added
 global routine _va
 global samplelist all${routine} youngold${routine} young${routine} old${routine} highcutoff${routine} digit6${routine} all_uw${routine} all_w0${routine} all_w25${routine}

 do "${code}/Makedata.do"
 do "${code}/Raw.do"
 do "${code}/Permute.do"
 do "${code}/Cov.do"

*Table A.1
do "${code}/Table.do"


*Tradables
 global routine _tradables
 global samplelist all${routine} youngold${routine} young${routine} old${routine} highcutoff${routine} digit6${routine} all_uw${routine} all_w0${routine} all_w25${routine}
 do "${code}/Fromrawdata_tradables.do"
 do "${code}/Makedata.do"
 do "${code}/Raw.do"
 do "${code}/Permute.do"
 do "${code}/Cov.do"

*Table A.4
do "${code}/Table.do"

*Sales per worker 
 global routine _spw
 global samplelist all${routine} youngold${routine} young${routine} old${routine} highcutoff${routine} digit6${routine} all_uw${routine} all_w0${routine} all_w25${routine}

 do "${code}/Makedata.do"
 do "${code}/Raw.do"
 do "${code}/Permute.do"
 do "${code}/Cov.do"

*Table A.5
do "${code}/Table.do"
